package com.topisv.tms.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.topisv.tms.entity.PipeStock;

public interface PipeStockDao extends PagingAndSortingRepository<PipeStock, Long>, JpaSpecificationExecutor<PipeStock>{
	/*@Modifying
	@Query("select st from Storage st where st.areaGroup.id = ?1")
	List<Storage> getByAreaGroupId(Long id);
	
	@Query("select st from Storage st where st.areaGroup.id = ?1 and st.type=?2")
	List<Storage> findByAreaGroup(Long areaGroupId,String type);*/
	
	@Query("select st from PipeStock st where st.pipe_code = ?1 and st.shelf_code=?2 order by st.shelf_code")
	List<PipeStock> findByPipeCode(String pipe_code,String shelf_code);
	@Query("select st from PipeStock st where st.stock_code = ?1")
	PipeStock findByStockCode(String stock_code);
	@Query("select st from PipeStock st where st.storage_code = ?1 order by st.stock_name")
	List<PipeStock> findByStorageCode(String storage_code);
	
	@Modifying
	@Query("delete from PipeStock p where P.storage_code = ?1")
	void deleteByStorageCode(String storage_code);
	
	@Query("select t from PipeStock t where t.customer_code = ?1 and t.areagroup_code=?2 and t.stock_code=?3")
	PipeStock loadByCondition(String customerCode, String warehouseCode,String stockCode);
}
